package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*护理计划相关的接口*/

@Slf4j
@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划相关的接口")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    // 3.1 查询所有护理计划
    @ApiOperation(value = "3.1查询所有护理计划Plan", notes = "查询所有护理计划")
    @GetMapping
    public ResponseResult selectAll() {
        List<NursingPlanVo> nursingPlanVoList =nursingPlanService.selectAll();
        return ResponseResult.success(nursingPlanVoList);
    }

    // 3.2 新增护理计划（包括护理项目，连NursingProjectPlan表。在查询NursingProject表）
    @ApiOperation(value = "3.2新增护理计划Plan", notes = "新增护理计划")
    @PostMapping
    public ResponseResult insertNursingPlan(
            @ApiParam(value = "新增的护理计划plan", required = true)
            @RequestBody NursingPlanDto nursingPlanDto) {
        nursingPlanService.insertNursingPlan(nursingPlanDto);

        return ResponseResult.success();
    }

    // 3.3 添加分页查询护理计划
    @ApiOperation("3.3根据名称和状态分页查询plan")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> searchNursingPlan(
            @ApiParam(value = "护理计划名称")
            @RequestParam(required = false) String name,
            @ApiParam(value = "护理计划状态")
            @RequestParam(required = false) Integer status,
            @ApiParam(value = "页码（默认为1）")
            @RequestParam(required = false, defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页大小（默认为10）")
            @RequestParam(required = false, defaultValue = "10") Integer pageSize) {

        return ResponseResult.success(nursingPlanService.listByPage(name, status, pageNum, pageSize));
    }

    //  3.4 根据id查询护理计划
    @ApiOperation("3.4根据id查询护理计划plan")
    @GetMapping("/{id}")
    public ResponseResult getNPById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id) {
       NursingPlanVo planVoPageResponse = nursingPlanService.getById(id);
        return ResponseResult.success(planVoPageResponse);
    }

    // 3.5 修改护理计划
    @ApiOperation("3.5修改护理计划plan")
    @PutMapping("/{id}")
    public ResponseResult updateNP(
            @ApiParam(value = "要修改护理计划plan", required = true)
            @RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updateNP(nursingPlanDto);
        return ResponseResult.success();
    }
    //  3.6 删除护理计划
    @ApiOperation("3.6删除护理计划plan")
    @DeleteMapping("/{id}")
    public ResponseResult deleteNPById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long nursingPlanId){
        nursingPlanService.deleteNPById(nursingPlanId);
        return ResponseResult.success();
    }

    // 3.7 启用/禁用护理计划
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("3.7启用/禁用护理计划")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id,
            @ApiParam(value = "状态，0：禁用，1：启用", required = true)
            @PathVariable Integer status) {
        nursingPlanService.enableOrDisable(id, status);
        return ResponseResult.success();
    }

}
